package com.zys.el.user.quartz;

import com.alibaba.fastjson.JSON;
import com.zys.el.user.config.po.Show;
import com.zys.el.user.po.User;
import com.zys.el.user.service.IUserService;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.List;

public class NoteDataQuartz extends QuartzJobBean {

    @Autowired
    private IUserService userService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        // 定时更新
        List<User> list = userService.list();
        for (User user : list) {
            Long id = user.getId();
            Show s = userService.getUserNoteDataByUserId(id);

            redisTemplate.opsForValue().set("ND" +user.getId(), JSON.toJSONString(s));
        }
        System.out.println("笔记数据加载结束！！！");
    }
}
